package lee.vioson.remotedata.bean

import com.google.gson.Gson
import com.google.gson.internal.`$Gson$Types`
import java.lang.reflect.Type

/**
 *Author:viosonlee
 *Date:2023/6/21
 *DESCRIPTION:
 */
//just for this project
val Int.boolean: Boolean
    get() = this == 1

fun Any.toJson(): String = Gson().toJson(this)

inline fun <reified T> String.toList(): List<T> {
    val listType: Type = `$Gson$Types`.newParameterizedTypeWithOwner(null, ArrayList::class.java, T::class.java)
    return if(!contains("[")){
        Gson().fromJson("[${this}]", listType)
    }else{
        Gson().fromJson(this, listType)
    }
}
inline fun <reified T>String.toObject():T{
    return Gson().fromJson(this,T::class.java)
}